<?php
function fw24h_db_connect( $_FW24H_CONFIG_) {
	global $_FW24H_USE_DB;
	if( $_FW24H_USE_DB) {
		$FW24H_ACTIVE_DB = mysql_connect( $_FW24H_CONFIG_['server'], $_FW24H_CONFIG_['username'], $_FW24H_CONFIG_['password']) or trigger_error( mysql_error(), E_USER_ERROR);
		mysql_select_db( $_FW24H_CONFIG_['database'], $FW24H_ACTIVE_DB) or trigger_error( mysql_error(), E_USER_ERROR);
	}
	return $FW24H_ACTIVE_DB;
}

function fw24h_db_query( $sql, $connection) {
	// log sql command
	if( DEBUG_MODE) {
		$f_error_msg = date( 'Y-m-d H:i:s')."; SQL: $sql\n";
		error_log( $f_error_msg, 3, APP_DIR.'/logs/sql.log');
	}
	$rs = mysql_query( $sql, $connection) or trigger_error( mysql_error().';;;'.$sql, E_USER_ERROR);
	return $rs;
}

function fw24h_db_insert_id( $connection) {
	return mysql_insert_id( $connection);
}

function fw24h_db_fetch_assoc( $result) {
	return mysql_fetch_assoc( $result);
}

function fw24h_db_free_result( $result) {
	return mysql_free_result( $result); 
}

function fw24h_db_fetch_array( $result, $connection) {
	return mysql_fetch_array( $result);
}

function fw24h_db_affected_rows( $connection) {
	return mysql_affected_rows( $connection);
}

function fw24h_db_close( $connection) {
	return mysql_close( $connection);
}

function fw24h_db_data_seek( $result, $number) {
	return mysql_data_seek( $result, $number);
} 

function fw24h_db_errno( $connection) {
	return mysql_errno( $connection);
}

function fw24h_db_error( $connection) {
	return mysql_error( $connection);
}



